package com.lsl.bhllserver.service.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lsl.bhllserver.entity.*;

@Service
public class RegisterService extends UserService {

    @Autowired
    private UserManageService userManageService;

    public Integer register(String username, String password, String role, String phone) {
        if (role.equals("customer")) {
            Customer newUser = (Customer)userManageService.addUser(() -> {
                return new Customer(null, username, password, phone, "(暂未设置)");
            });
            return newUser.getId();
        } else if (role.equals("business")) {
            Business newUser = (Business)userManageService.addUser(() -> {
                return new Business(null, username, password, phone, "(暂未设置)", "(暂未设置)");
            });
            return newUser.getId();
        } else {
            System.out.println("+++++ 角色不对？？？？");
            return 0;
        }
    }

    // public boolean register(String username, String password, String role, String phone) {
    //     if (role.equals("customer")) {
    //         //customerDAO.setTypeflag(new Customer());
    //         Customer customer = new Customer(null, username, password, phone, null);
    //         customerDAO.insert(customer);
    //         return true;
    //     } else if (role.equals("business")) {
    //         //businessDAO.setTypeflag(new Business());
    //         Business business = new Business(null, username, password, phone, null, null);
    //         businessDAO.insert(business);
    //         return true;
    //     } else {
    //         System.out.println("+++++ 角色不对？？？？");
    //         return false;
    //     }

    // }
}
